package com.example.ck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ck.dao.MessageDao;
import com.example.ck.entity.Message;
import com.example.ck.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审核消息通知表(Message)表服务实现类
 *
 * @author makejava
 * @since 2024-04-06 16:03:06
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    /**
     * 添加一个条新的审核意见信息
     *
     * @param message
     */
    @Override
    public Message addMessage(Message message) {
        messageDao.insert(message);
        return message;
    }

    @Override
    public List<Message> getMessageByProjectId(int projectId) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("project_id", projectId);
        List list = messageDao.selectList(qw);
        return list;
    }

    /**
     * 根据项目id查询专家对这个项目的审核状态
     *
     * @param projectId
     * @return
     */
    @Override
    public List<Message> getMessageStatusByProjectId(int projectId) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("project_id", projectId);
        List list = messageDao.selectList(qw);
        return list;
    }

    /**
     * 根据项目id和专家名称查询是否有审核意见
     *
     * @param projectId
     * @param name
     * @return
     */
    @Override
    public Message getMessageByProjectIdAndName(int projectId, String name) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("project_id", projectId);
        qw.eq("name", name);
        Message message = messageDao.selectOne(qw);
        return message;
    }
}
